package cn.biplam.back.services.rmiregist;


import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import cn.biplam.back.services.snr.ServiceNameRegister;
import cn.biplam.common.tools.DEBUG;
import cn.biplam.common.wrapper.ErrorMessage;

  
/**
 * 注册服务
 * @author 	WangSong 2009-3-30 下午05:43:05
 * @version 1.0
 */
public class RmiRegister extends GenericServlet   {   
  
        
	private static final long serialVersionUID = 1L;
    
	/**
	 * 注册服务
	 */
	public void init(ServletConfig config) throws ServletException   {  
        try{
        	ServiceNameRegister snr = new ServiceNameRegister();
        	Thread t = new Thread(snr);
        	if(isUnlimitied()){
        		t.run();     
        	}else{
        		DEBUG.println("服务注册超时!");
        	}
        }catch (Exception e){
            e.printStackTrace();
        }
    }
	
	/**
	 * 获取是否超过使用期限
	 * @return
	 * @throws ErrorMessage
	 */
	boolean isUnlimitied() throws ErrorMessage{
		boolean before = false;
    	try{
    		Calendar cal = Calendar.getInstance();
    		cal.setTime(new java.util.Date());
    		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    		java.util.Date lastDate = df.parse("2010-12-31 00:00:00");
    		Calendar last = Calendar.getInstance();
    		last.setTime(lastDate);
    		before = cal.before(last);
    	}catch (Exception e) {
    		e.printStackTrace();
		}
		return before;
	}

	@Override
	public void service(ServletRequest arg0, ServletResponse arg1)
			throws ServletException, IOException {
		
	}   
}   

